<div data-hook="admin_customer_detail_form_fields">

  <div class="panel panel-default" data-hook="customer_guest">

    <div class="panel-heading">
      <h1 class="panel-title">
        <%= Spree.t(:account) %>
      </h1>
    </div>

    <div class="panel-body">
      <div data-hook="customer_fields" class="row">
        <div class="col-md-8">
          <div class="form-group">
            <%= f.label :email, Spree.t(:email) %>
            <% if can? :edit, @order.user %>
              <%= f.email_field :email, class: 'form-control' %>
            <% else %>
              <p><%= @order.user.try(:email) || @order.email %></p>
            <% end %>
          </div>
        </div>
        <div class="col-md-4">
          <div class="form-group">
            <strong><%= label_tag nil, Spree.t(:guest_checkout) %></strong>
            <% if @order.completed? %>
              <div>
                <span class="badge">
                  <%= @order.user.nil? ? Spree.t(:say_yes) : Spree.t(:say_no) %>
                </span>
              </div>
            <% else %>
              <% guest = @order.user.nil? %>
              <div class="radio no-margint">
                <%= label_tag :guest_checkout_true do %>
                  <%= radio_button_tag :guest_checkout, true, guest %>
                  <%= Spree.t(:say_yes) %>
                <% end %>
              </div>
              <div class="radio">
                <%= label_tag :guest_checkout_false do %>
                  <%= radio_button_tag :guest_checkout, false, !guest, disabled: @order.cart? %>
                  <%= Spree.t(:say_no) %>
                <% end %>
              </div>
              <%= hidden_field_tag :user_id, @order.user_id %>
            <% end %>
          </div>
        </div>
      </div>
    </div>

  </div>

  <div class="row">
    <div data-hook="bill_address_wrapper" class="col-md-6">
      <div class="panel panel-default">
        <div class="panel-heading">
          <h1 class="panel-title"><%= Spree.t(:billing_address) %></h1>
        </div>

        <div class="panel-body">
          <% if can? :edit, @order.user %>
            <%= f.fields_for :bill_address do |ba_form| %>
              <%= render 'spree/admin/shared/address_form', f: ba_form, type: "billing" %>
            <% end %>
          <% else %>
            <%= render 'spree/admin/shared/address', address: @order.bill_address %>
          <% end %>
        </div>
      </div>
    </div>

    <div class="col-md-6" data-hook="ship_address_wrapper">
      <div class="panel panel-default">
        <div class="panel-heading">
          <h1 class="panel-title"><%= Spree.t(:shipping_address) %></h1>
        </div>
        <div class="panel-body">
          <% if can? :edit, @order.user %>
            <%= f.fields_for :ship_address do |sa_form| %>
              <div class="form-group">
                <span data-hook="use_billing">
                  <%= check_box_tag 'order[use_billing]', '1', @order.shipping_eq_billing_address? %>
                  <%= label_tag 'order[use_billing]', Spree.t(:use_billing_address) %>
                </span>
              </div>

              <%= render 'spree/admin/shared/address_form', f: sa_form, type: 'shipping' %>
            <% end %>
          <% else %>
            <%= render 'spree/admin/shared/address', address: @order.ship_address %>
          <% end %>
        </div>
      </div>
    </div>
  </div>

  <% if can? :edit, @order.user %>
    <div class="form-actions" data-hook="buttons">
      <%= button Spree.t('actions.update'), 'save' %>
    </div>
  <% end %>
</div>
